package br.unifor.cct.mia.dataenhancement;

import java.awt.Point;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Tuple implements Serializable {

	private List list;
	public boolean first = false;
	
	public Tuple () {
		list = new ArrayList();
	}
	
	public void addValue(String str) {
		list.add(str);
	}
	
	public String string(String[] values) {
		String str = (String)list.get(0);

		for (int i = 0; i < values.length; i++) {
			str = str.replaceFirst("X", values[i]);
		}
		
		return str;
	}
	
	public String stringWithValues(List positions, double[] array, Structure st) {
			
		Point pt;
		Attribute att;
		String str = (String)list.get(0);		
		StringBuilder builder = new StringBuilder(str);
		
		String v = null;
		for (int i = 0; i < array.length; i++) {
			pt = (Point)positions.get(i);
			att = st.getAttribute(pt.y); 
			
			if (att.getTipo().equalsIgnoreCase(Attribute.CONTINUOUS))
				if (att.isInteger()) v = Integer.toString((int)array[i]);
				else v = Double.toString(array[i]);
			else {				
				try {
					v = (String)st.getValues(att).get((int)array[i]);
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
			
			int index = builder.indexOf("X");
			builder.deleteCharAt(index);
			builder.insert(index, v);
		}
		
		
		return builder.toString();
	}
	
	public String stringWithValues(List positions, String[] valores, Structure st) {

		String str = (String)list.get(0);		
		StringBuilder builder = new StringBuilder(str);
	
		for (int i = 0; i < valores.length; i++) {
			int index = builder.indexOf("X");
			builder.deleteCharAt(index);
			builder.insert(index, valores[i]);
		}
		
		
		return builder.toString();
	}
	
}
